import {
	mapState
} from 'vuex'
import store from "@/store"

// 尝试将用户在根目录中的store/index.js的vuex的state变量，全部加载到全局变量中
let $uStoreKey = [];
try {
	$uStoreKey = store.state ? Object.keys(store.state) : [];
} catch (e) {

}


module.exports = {
	beforeCreate() {
		this.setCurrentUserLabel = (value) => {
			this.$store.commit('$setCurrentUserLabel', value);
		}
		this.getUserLocalStorage = ()=>{
			this.$store.commit('$getUserLocalStorage');
		}
		this.removeCurrentUserLabel = () =>{
			this.$store.commit('$removeCurrentUserLabel');
		}
		this.$u.vuex = (name, value) => {
				this.$store.commit('$stateSave', {
					name,
					value
				})
			},
			this.$u.localSave = (name, value) => {
				this.$store.commit('$localSave', {
					name,
					value
				})
			}
	},
	computed: {
		// 将vuex的state中的所有变量，解构到全局混入的mixin中
		...mapState($uStoreKey)
	}
}
